package com.sensors;

import android.util.Log;

/**
 * Created by tjpu on 2016/10/12.
 */
public class Acceleration {
    static String thisLogTag = "Acceleration";

    public double receivePeriod = 0.1;
    public static double CONVERT_TO_METRIC = 1.0/1024.0;

    long lastTime = System.currentTimeMillis();
    public double[] origin = {0.0, 0.0, 0.0};
    double[] metricUnit = {0.0, 0.0, 0.0};

    public int notReceive = 0;
    public boolean isNotReceive = false;

    public void putOrigin(double[] acce) {
        for(int i=0; i<origin.length && i < acce.length; i++) {
            origin[i] = acce[i];
        }

        convert();
        judge();
        filter();

        notReceive = 0;
        isNotReceive = false;
        receivePeriod = (System.currentTimeMillis() - lastTime) /  1000.0;
        lastTime = System.currentTimeMillis();
        Log.i(thisLogTag,"receive period: "+receivePeriod);
    }

    public double[] getMetric() {
        double[] returnData = new double[metricUnit.length];
        System.arraycopy(metricUnit,0,returnData,0,returnData.length);
        return returnData;
    }

    void convert() {
        for(int i=0; i<origin.length; i++) {
            metricUnit[i] = origin[i] * CONVERT_TO_METRIC;
        }
    }

    void judge() {

    }
    void filter() {

    }
}
